/**
 * 
 */
package infomanager;

import info.Subject;

/**
 * @author vtkhanh
 * 
 */
public class SubjectManager {
    private static Subject[] sSubjects;
    private static int sSubjectNum = 0;
    private static int sCount = 0;

    public static Subject[] getSubjects() {
	if (sSubjects == null) {
	    sSubjects = new Subject[sSubjectNum];
	}
	return sSubjects;
    }
    
    public static Subject getSubjectById(int id) {
	for (Subject subject : sSubjects) {
	    if (subject.getSubjectId() == id) {
		return subject;
	    }
	}
	return null;
    }
    
    public static void addSubject(Subject subject) {
	if (sSubjectNum == 0) {
	    throw new ArrayIndexOutOfBoundsException();
	}	
	if (sCount < sSubjectNum) {
	    if (sSubjects == null) {
		sSubjects = new Subject[sSubjectNum];
	    }
	    sSubjects[sCount] = subject;
	    sCount++;
	}
    }

    public static void setSubjects(Subject[] subjects) {
	SubjectManager.sSubjects = subjects;
    }

    public static void setNumberOfSubjects(int num) {
	sSubjectNum = num;
    }
    
    public static int getNumberOfSubjects() {
	return sSubjectNum;
    }
    
}
